#!/usr/bin/python
# -*- coding: UTF-8 -*-

import MySQLdb

# 打开数据库连接
db = MySQLdb.connect("localhost", "root", "123456", "python-web-study", charset='utf8' )

# 使用cursor()方法获取操作游标
cursor = db.cursor()

# SQL 查询语句
sql = "SELECT * FROM USER"
try:
   # 执行SQL语句
   cursor.execute(sql)
   # 获取所有记录列表
   results = cursor.fetchall()
   for row in results:
      username = row[0]
      password = row[1]
      # 打印结果
      print("username=%s,password=%s" % \
             (username, password))
except:
   print("Error: unable to fetch data")

# 关闭数据库连接
db.close()
